<?php

	class WS_DepartmentSubjectCourseCon {
		
		private $DBADMIN;
		private $HASHID;
		
		public function __construct() {

			$this->DBMOD 	= new WS_DepartmentSubjectCourseMod();
			$this->HASHID 	= sha1(time());

		}
		
		public function gradeConvertion() {
			return array('1.0', '1', '1.25', '1.50', '1.5', '1.75', '2.0', '2', '2.25', '2.50', '2.5', '2.75', '3.0', '3', '4.0', '4', '5.0', '5', 'DRP', 'INC');
		}
		
		public function getListDepartment($strID = '') {
			
			return $this->DBMOD->getListDepartment($strID);

		}
		
		public function getListSection() {
				
			return $this->DBMOD->getListSection();
	
		}
		
		public function getProfListSection($strSubjects) {
				
			return $this->DBMOD->getProfListSection($strSubjects);
	
		}
		
		public function getListSemesters() {
				
			return $this->DBMOD->getListSemesters();
	
		}
		
		public function getDepartment($strID) {
			
			return $this->DBMOD->getDepartment($strID);
			
		}
		
		public function getListCourses($strID) {
			
			return $this->DBMOD->getListCourses($strID);
			
		}
		
		public function getChecklistHeader($strID) {
			
			return $this->DBMOD->getChecklistHeader($strID);
			
		}
		
		public function insertUpdateCheckListHeader($strArray) {
			
			$headID 	= $strArray['head_idPK'];
			$headBased 	= $strArray['head_based'];
			$headYear 	= $strArray['head_year'];
			$deptID 	= $strArray['dept_idFK'];
			
			if ( !empty($headID) ) {
				
					   $this->DBMOD->updateCheckListHeader($deptID);
				return $this->DBMOD->insertCheckListHeader($headYear, $headBased, $deptID);
				
			}
		}
		
		public function getCourse($strID) {
			
			return $this->DBMOD->getCourse($strID);
			
		}
		
		public function insertCourse($strArray) {
			
			return $this->DBMOD->insertCourse($strArray);
			
		}
		
		public function updateCourse($strArray, $strID) {
			
			return $this->DBMOD->updateCourse($strArray, $strID);
			
		}
		
		public function deleteCourse($strID) {
			
			return $this->DBMOD->deleteCourse($strID);
			
		}
		
		public function getSemesterIrregular($strCourseID, $strStudID) {
			
			$return = $this->DBMOD->getSemesterIrregular($strCourseID, $strStudID);
			$arr = array();
			if ( !empty($return) ) {
				foreach($return as $value) {
					$arr[] = $value['sem_idFK'];
				}
			}
			$nextArrValidate = max($arr) + 1;
			$nextSemesterIsActive = $this->DBMOD->getNextSemesterIsActive($nextArrValidate, $strCourseID);
			
			$nextArr = ( $nextSemesterIsActive['count'] > 0 ) ? array(max($arr) + 1) : array(max($arr) + 2);
			
			$mergeArr = array_merge($arr, $nextArr);
			
			$semDescLinker = $this->DBMOD->getSemesterIrregularLinkerDesc($mergeArr);
			
			return $semDescLinker;
			
		}
		
		public function getSemesterLinker($strCourseID, $strSemesterActive = '', $strIsDeleted = true) {
			
			return $this->DBMOD->getSemesterLinker($strCourseID, $strSemesterActive, $strIsDeleted);
			
		}
		
		public function getSemesterLinkerEnrolled($strCourseID, $strStudID) {
			
			return $this->DBMOD->getSemesterLinkerEnrolled($strCourseID, $strStudID);
			
		}
		
		public function getSemesterLinkerKeyArrangement($strCourseID, $nextSemester = '', $isMultple = 0) {
			
			$return = $this->DBMOD->getSemesterLinkerKeyArrangement($strCourseID, $nextSemester, $isMultple);
			if ( !empty($return) ) {
				return $return;
			}
			else {
				return $this->DBMOD->getSemesterLinkerKeyArrangementLastSemester($strCourseID, $nextSemester);
			}
			
		}
		
		public function getSemesterLinkerPreviousSemester($strCourseID, $nextSemester = '') {
			
			$return = $this->DBMOD->getSemesterLinkerPreviousSemester($strCourseID, $nextSemester);
			
			$countSubj = array();
			if ( !empty($return) ) {
				foreach($return as $res) {
					$countSubj[] = $this->DBMOD->getCountSubjectAll($res['sem_linker_idPK']);
				}
			}
			
			return $countSubj;
		}
		
		public function getCountSubjectTaken($strStudID, $strCourseID, $semesterLinker) {
		
			return $this->DBMOD->getCountSubjectTaken($strStudID, $strCourseID, $semesterLinker);
			
		}
		
		public function getFreshmenSemesterLinker($strCourseID) {
			
			return $this->DBMOD->getFreshmenSemesterLinker($strCourseID);
			
		}
		
		public function getSemesterLabel($strSemID) {
		
			return $this->DBMOD->getSemesterLabel($strSemID);
			
		}
		
		public function getSemesterLabelValidate($strSemID, $strStudID) {
		
			return $this->DBMOD->getSemesterLabelValidate($strSemID, $strStudID);
			
		}
			
		public function getSemesterLabelCredits($strStudID) {
			
			return $this->DBMOD->getSemesterLabelCredits($strStudID);

		}
			
		public function getSemIDNoRecord($course_id, $year_id) {
			
			$return = $this->DBMOD->getSemIDNoRecord($course_id, $year_id);
			
			return $return['sem_linker_idPK'];

		}
		
		public function getCourseHeader($strDeptID) {
			
			return $this->DBMOD->getCourseHeader($strDeptID);
		}
		
		public function getSubjectListingSemLinker($strSemLinkerID, $activeYear) {
		
			return $this->DBMOD->getSubjectListingSemLinker($strSemLinkerID, $activeYear);
			
		}
		
		public function getStudentSubjectSemLinkerCurriculum($strStudID, $strCourseID, $strSemLinkerID) {
			
			return $this->DBMOD->getStudentSubjectSemLinkerCurriculum($strStudID, $strCourseID, $strSemLinkerID);
			
		}
		
		public function getStudentSemesterActiveYear($strStudID, $strCourseID, $strSemLinkerID) {
			
			return $this->DBMOD->getStudentSemesterActiveYear($strStudID, $strCourseID, $strSemLinkerID);
			
		}
		
		public function getListSemestersDefault() {
				
			return $this->DBMOD->getListSemestersDefault();
			
		}
		
		public function getSemesterLinkerNote($strSem, $strCourse, $strYear) {
			
			return $this->DBMOD->getSemesterLinkerNote($strSem, $strCourse, $strYear);
			
		}
		
		public function getTotalUnitsPerSemesterLinker($strSemLinkerID, $strStudID = '') {
			
			$result = $this->DBMOD->getTotalUnitsPerSemesterLinker($strSemLinkerID, $strStudID);

			$returnValue = 0;
			if(!empty($result)) {
				foreach($result as $resValue) {
					$returnValue += $resValue['abs_total_units'];
				}
			}
			
			return $returnValue;
			
		}
		
		public function getTotalUnitsPerSemesterLinkerActive($strSemLinkerID, $strStudID = '') {
			
			$result = $this->DBMOD->getTotalUnitsPerSemesterLinkerActive($strSemLinkerID, $strStudID);

			$returnValue = 0;
			if(!empty($result)) {
				foreach($result as $resValue) {
					$returnValue += $resValue['abs_total_units'];
				}
			}
			
			return $returnValue;
			
		}
		
		public function insertSemLinker($strSem, $strCourse, $strHead, $strYear) {
			
			return $this->DBMOD->insertSemesterLinker($strSem, $strCourse, $strHead, $strYear);
			
		}
		
		public function udpateSaveSemLinkerNote($strSemLinkerID, $strNoteValue) {
			
			return $this->DBMOD->udpateSaveSemLinkerNote($strSemLinkerID, $strNoteValue);
			
		}
		
		public function updateSemLinker($strSemLinkerID) {
			
			$this->DBMOD->updateSemLinker($strSemLinkerID);
			
		}
		
		public function deleteSemLinker($strSemLinker) {
			
				return $this->DBMOD->deleteSemLinker($strSemLinker);
			
		}
		
		public function getSubject($strSubjID) {
			
			return $this->DBMOD->getSubject($strSubjID);
			
		}
		
		public function getSubjectPerCourse($strCourseID) {
			
			return $this->DBMOD->getSubjectPerCourse($strCourseID);
			
		}
		
		public function getSubjectCourse() {
			
			$result = $this->DBMOD->getSubjectCourse();
			
			if(!empty($result)) {
				foreach($result as $resultField => $resultValue) {
					$res[$resultValue['course_desc']][$resultValue['sem_desc']][] = $resultValue;
				}
			}
			
			return $res;
			
		}
		
		public function insertSubject($strArray) {
		
			return $this->DBMOD->insertSubject($strArray);
			
		}
		
		public function getSubjRequisite($strSubjID) {
		
			return $this->DBMOD->getSubjRequisite($strSubjID);
		
		}
		
		public function getSubjCourseRequisite($strCourseID) {
					
			$result = $this->DBMOD->getSubjCourseRequisite($strCourseID);
			
			if(!empty($result)) {
				foreach($result as $resultField => $resultValue) {
					$res[$resultValue['subj_idFK']][] = $resultValue;
				}
			}
			
			return $res;
			
		}
		
		public function updateSubject($strArray, $strSubjID) {
		
			return $this->DBMOD->updateSubject($strArray, $strSubjID);
			
		}
		
		public function deleteSubject($strSubjID) {

			return $this->DBMOD->deleteSubject($strSubjID);
			
		}
		
		public function requisite($strSubjLinkerID) {
			
			return $this->DBMOD->requisite($strSubjLinkerID);
			
		}
		
		public function getInputGradeRequisite($strSubjLinkerID, $strSemLinkerActiveID, $strStudID, $strCourseID) {
			
			$result = $this->DBMOD->getInputGradeRequisite($strSubjLinkerID, $strSemLinkerActiveID, $strStudID, $strCourseID);
			
			if (!empty($result)) {
				foreach($result as $resultValue) {
					$return[$resultValue['sem_linker_idFK']][] = $resultValue;
				}
			}
			
			return $return;
			
		}
		
		public function getSemesterLinkerFouthYear($strYear, $strActiveSem) {
			
			$result = $this->DBMOD->getSemesterLinkerFouthYear($strYear, $strActiveSem);
			
			return $result['sem_linker_idPK'];
		}
		
		public function getStudentNextSubjectDetails($strSubjLinkerID) {
			
			$result = $this->DBMOD->getStudentNextSubjectDetails($strSubjLinkerID);
			
			if (!empty($result)) {
				foreach($result as $resultValue) {
					$return[$resultValue['sem_linker_idFK']][] = $resultValue;
				}
			}
			
			return $return;
			
		}
		
		public function getRequisiteSubject($strSubjRequisite, $strCourse = '') {
			
			$strSubjRequisiteSpaces = str_replace(' ', '', $strSubjRequisite);
			$strSubjRequisiteArr 	= (!empty($strSubjRequisiteSpaces)) ? explode(',', $strSubjRequisiteSpaces) : array();

			$str3rd4th = array('3rdYr', '4thYr');

			if (!empty($strSubjRequisiteArr)) {
				$strSubjRequisiteResultRemove  = array_diff($strSubjRequisiteArr, $str3rd4th);
				$strSubjRequisiteResultCompare = array_intersect($strSubjRequisiteArr, $str3rd4th);
			}
			$result = $this->DBMOD->getRequisiteSubject($strSubjRequisiteResultRemove, $strCourse);

			$result3rd4th = "";
			if (!empty($strSubjRequisiteResultCompare)) {
				foreach($strSubjRequisiteResultCompare as $strSubjRequisiteResultCompareValue) {
					
					if ( $strSubjRequisiteResultCompareValue == '3rdYr' ) {
						$result3rd4th .= "3Yr-";
					}
					
					if ( $strSubjRequisiteResultCompareValue == '4thYr' ) {
						$result3rd4th .= "4Yr-";
					}
					
				}
			}

			$resultReq = "";
			if ( !empty($result) ) {
				foreach($result as $resultValue) {
					$resultReq .= $resultValue['subj_idPK'] . "-";
				}
			}
			
			return trim(rtrim($result3rd4th . $resultReq, '-'));

		}
		
		public function getReqSubjectID($strSubjRequisite, $strSubjEditOrNot = true) {
			
			$strSubjRequisiteArr =  (!empty($strSubjRequisite)) ? explode('-', $strSubjRequisite) : array();
			
			$str3rd4th 			 = array('3Yr', '4Yr');
			
			$strSubjRequisiteResultRemove  = array_diff($strSubjRequisiteArr, $str3rd4th);
			$strSubjRequisiteResultCompare = array_intersect($strSubjRequisiteArr, $str3rd4th);
			
			$result = $this->DBMOD->getReqSubjectID($strSubjRequisiteResultRemove);
			
			if ( $strSubjEditOrNot == true ) {
				$result3rd4th = "";
				if (!empty($strSubjRequisiteResultCompare)) {
					foreach($strSubjRequisiteResultCompare as $strSubjRequisiteResultCompareValue) {
							$value3rd4th .= $strSubjRequisiteResultCompareValue . '-';
					}
					switch ($value3rd4th) {
						case '3Yr-4Yr-': $result3rd4th = "3rd/4th Yr. Standing, "; 	break;
						case '3Yr-': 	 $result3rd4th = "3rd Yr. Standing, ";  		break;
						case '4Yr-': 	 $result3rd4th = "4th Yr. Standing, ";  		break;
					}
				}
				
				$resultReq = "";
				if ( !empty($result) ) {
					$resultReqS = (max(array_keys($result)) - 1);
					foreach($result as $resultField => $resultValue) {
						$seperater  = ($resultField == $resultReqS) ? " & " : ", ";
						$resultReq .= $resultValue['subj_code'] . $seperater;
					}
				}
			}
			else {
				$result3rd4th = "";
				if (!empty($strSubjRequisiteResultCompare)) {
					foreach($strSubjRequisiteResultCompare as $strSubjRequisiteResultCompareValue) {
							$value3rd4th .= $strSubjRequisiteResultCompareValue . ',';
					}
					switch ($value3rd4th) {
						case '3Yr,4Yr,':
						case '4Yr,3Yr,': $result3rd4th = "3rdYr, 4thYr, "; break;
						case '3Yr,'	: $result3rd4th = "3rdYr, ";  		break;
						case '4Yr,'	: $result3rd4th = "4thYr, ";  		break;
					}
				}
				
				if ( !empty($result) ) {
					$resultReq = "";
					$resultReqS = (max(array_keys($result)) - 1);
					foreach($result as $resultField => $resultValue) {
						$resultReq .= $resultValue['subj_code'] . ', ';
					}
				}
			}
			
			return trim(rtrim($result3rd4th . $resultReq, ', '));
			
		}
		
		public function getReqSubjectIDEdit($strSubjRequisite) {
			
			$strSubjRequisiteArr 	= explode('-', $strSubjRequisite);
			
			$result = $this->DBMOD->getReqSubjectID($strSubjRequisiteArr);
			
			if ( !empty($result) ) {
				$resultReq = "";
				$resultReqS = (max(array_keys($result)) - 1);
				foreach($result as $resultField => $resultValue) {
					$resultReq .= $resultValue['subj_code'] . ', ';
				}
				return trim(rtrim($resultReq, ', '));
			}
		}
		
		public function getFees() {
			
			return $this->DBMOD->getFees();
			
		}
		
		public function deleteSemesterFeesActive($strSemFeesLinkerID) {
			
			$this->DBMOD->deleteSemesterFeesActive($strSemFeesLinkerID);
			
		}		
		
		
		public function getSemFeesLinker($strSFLID) {
			
			return $this->DBMOD->getSemFeesLinker($strSFLID);
			
		}
		
		public function getTotalUnitsPerSemester($strSLID) {
			
			return $this->DBMOD->getTotalUnitsPerSemester($strSLID);
			
		}
		
		public function getSemFeesLinkerListing($strSLID) {
						
			return $this->DBMOD->getSemFeesLinkerListing($strSLID);
			
		}
		
		public function getSemFeesLinkerListingActive($strSLID) {
						
			return $this->DBMOD->getSemFeesLinkerListingActive($strSLID);
			
		}
		
		public function getSemFeesTotalAmount($strSLID, $totalUnits) {
			
			$result = $this->DBMOD->getSemFeesLinkerListing($strSLID);
			
			if (!empty($result)) {
				$amountTotalValue = 0;
				foreach($result as $resultValue) {
					
					$descVal = ( $resultValue['fee_idFK'] == 1 ) ? (int)$totalUnits * (int)$resultValue['amount'] : $resultValue['amount'];
					
					$amountTotalValue += $descVal;
				}
				
				return $amountTotalValue;
			}
			
		}
		
		public function insertSemFeesLinker($strSFLID, $strFee, $strAmount) {
			
			return $this->DBMOD->insertSemFeesLinker($strSFLID, $strFee, $strAmount);
			
		}
		
		public function updateSemFeesLinker($strSFLID, $strFee, $strAmount, $strSFLID) {
			
			return $this->DBMOD->updateSemFeesLinker($strSFLID,$strFee, $strAmount, $strSFLID);
			
		}
		
		public function getSemLinkerFeeSemesterLinker($strSFLID) {
			
			return $this->DBMOD->getSemLinkerFeeSemesterLinker($strSFLID);
			
		}
		
		public function insertStudentPaymentHistory($strActiveSem, $strStudID, $strCourseID, $strAmount, $strPaymentMethod) {
			
			$this->DBMOD->insertStudentPaymentHistory($strActiveSem, $strStudID, $strCourseID, $strAmount, $strPaymentMethod);
			
		}
		
		public function getStudentPaymentHistory($strActiveSem, $strStudID, $strCourseID) {
			return $this->DBMOD->getStudentPaymentHistory($strActiveSem, $strStudID, $strCourseID);
			
		}
		
		public function getProfSubjectList($strProf, $strSubjID = '', $strEqualSubjID = true) {
			
			return $this->DBMOD->getProfSubjectList($strProf, $strSubjID, $strEqualSubjID);
		}
		
		public function getRoomsDepartment($strDept) {
			
			return $this->DBMOD->getRoomsDepartment($strDept);
			
		}
		
		public function insertDeptRooms($strArray) {
			
			return $this->DBMOD->insertDeptRooms($strArray);
			
		}
		
		public function updateDeptRooms($strRooms) {
				
			return $this->DBMOD->updateDeptRooms($strRooms);
				
		}
		
		public function getSeectionList($strCourseID) {
			
			return $this->DBMOD->getSeectionList($strCourseID);
			
		}
		
		public function insertUpdateProfSubj($strSubj, $strProf, $strAction, $strYear = '') {
			
			if ( $strAction == 1 ) 
				$this->DBMOD->insertProfSubj($strSubj, $strProf, $strYear);
			else $this->DBMOD->updateProfSubj($strSubj, $strProf, $strYear);
			
		}
		
		public function getStudentSemesteryearCourse($strStudID, $strCourseID) {
			
			return $this->DBMOD->getStudentSemesteryearCourse($strStudID, $strCourseID);
			
		}
		
		public function getSemesterDescViaLinker($strSemLinkerID) {
			
			return $this->DBMOD->getSemesterDescViaLinker($strSemLinkerID);
			
		}
		
		public function inputGradeRequisiteGradeIfDrop($strSubjID, $strSemLinkerID, $studID) {
			
			return $this->DBMOD->inputGradeRequisiteGradeIfDrop($strSubjID, $strSemLinkerID, $studID);
			
		}
		
		public function getSemesterSY() {

			return $this->DBMOD->getSemesterSY();
			
		}
		
		public function getNextSummerSY() {
			$return = $this->DBMOD->getNextSummerSY();
			return $return['count'];
		}
		
	}
?>